import React, { Component } from 'react';
/*
1 componentWillUnmount
组件卸载时
*/
class Demo extends Component{
  render(){
    return <h1>Demo组件</h1>
  }; 
  componentDidMount(){
this.timeId = setInterval(()=>{
console.log(1);
},1000);
  };
  componentWillUnmount(){
    console.log("Demo 组件卸载");
    clearInterval(this.timeId);
  };
}
class App extends Component {
  state ={
    show:true,
  };
  handleClick=(params) => {
    this.setState({
      show:false,
    });
  };
  render() {
    return (
      <div>
        {
          this.state.show?<Demo></Demo>:" "
        }
      
        <button onClick = {this.handleClick}>卸载组件</button>
      </div>
    );
  }
}

export default App;
